package problem;

import java.util.HashSet;
import java.util.Set;
import java.util.TreeSet;

/**
 * @author RunningShrimp
 * @date 2021/5/16  20:15
 * @see <a href="https://leetcode-cn.com/problems/unique-morse-code-words/">唯一摩尔斯密码词</a>
 */
public class UniqueMorseCodeWords {
    public int uniqueMorseRepresentations(String[] words) {
        if (words == null || words.length == 0) {
            return 0;
        }
        String[] codes = {".-", "-...", "-.-.", "-..", ".", "..-.", "--.", "....", "..", ".---", "-.-", ".-..", "--", "-.", "---", ".--.", "--.-", ".-.", "...", "-", "..-", "...-", ".--", "-..-", "-.--", "--.."};
        Set<String> morse = new HashSet<>();
        for (String word : words) {
            byte[] bytes = new byte[1024];
            StringBuilder sb = new StringBuilder();
            for (int i = 0; i < word.length(); i++) {
                sb.append(codes[word.charAt(i) - 'a']);
            }
            morse.add(sb.toString());
        }
        return morse.size();
    }
}
